<?php
// $Id: mod_jtsassured.php,v 1.0.0B 20/09/2007 22:12:19 RussW $
/**
 * JTSassured Site Module has been designed to display your JTSc Assessment Rating
 * to yur site visitors. It is configurable as to what can be seen if the Rating
 * is below an acceptable level of 90%, displaying three levels of Assurance,
 * 90%, 95% and 100%.
 *
 * @package mod_jtsassured
 * @copyright (C) Copyright 2007 JustJoomla! All Rights Reserved.
 * @license GNU/GPL
 * @author RussW <enquiries@justjoomla.com.au>
 */
// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

GLOBAL $mosConfig_dbprefix;

		if (!file_exists( 'includes/version.php' )) {
			$isV15 = "1";
		}

	// Joomla! Parameter Definitions
	$params->def('JTSassuredmode', 1);
	$params->def('imageLinkJTS', 1);
	$params->def('ratingNotAttained', 1);
	$params->def('authorLink', 1);
	$params->def('downloadLink', 1);
	$params->def('cScheme', a);
	$params->def('customHeader', none);
	$params->def('customText', none);

	// Colour Scheme Definitions
	$colorScheme = $params->get('cScheme');
	$customHeader = $params->get('customHeader');
	$customText = $params->get('customText');

	// Icon Definitions
	$downloadIcon	= "administrator/images/download_f2.png";
	$JTSLogo		= "administrator/components/com_jts/images/jts.gif";

	// Debug
	/***
	if ($params->get('imageLinkJTS')) { echo "imageLinkJTS = yes<br />"; } else { echo "imageLink = no<br />"; }
	if ($params->get('ratingNotAttained')) { echo "ratingNotAttained = yes<br />"; } else { echo "ratingNotAttained = no<br />"; }
	if ($params->get('authorLink')) { echo "authorLink = yes<br />"; } else { echo "authorLink = no<br />"; }
	$customHeader = $params->get('customHeader');
	if ($params->get('customHeader')) { echo "customHeader = ".$customHeader."<br />"; } else { echo "customHeader = none<br />"; }
	$customText = $params->get('customText');
	if ($params->get('customText')) { echo "customText = ".$customText."<br />"; } else { echo "customText = none<br />"; }
	echo "colorScheme: ". $colorScheme ."<br /><hr />";
	***/
?>

<style type="text/css">
	/* .xsnazzy h1, .zsnazzy h1 { margin:0; font-size:1.2em; padding:0 10px 5px 10px; border-bottom:1px solid #444; } */
	.xsnazzy div.h1, .zsnazzy div.h1 { margin:0; font-size:0.8em; padding:0 10px 5px 10px; border-bottom:1px solid #444; }
	.xsnazzy div.h2, .zsnazzy div.h2 { margin:0; font-size:0.8em; padding:5px 10px 0 10px; border-top:1px solid #444; }
	.xsnazzy p, .zsnazzy p { margin:0; padding:5px 10px; font-size:10px; }
	/* .xsnazzy { background: transparent; width:120px; float:left; margin:0 3px; } */
	.xsnazzy { background: transparent; width:120px; margin:0 3px; }

	.xtop, .xbottom { display:block; background:transparent; font-size:1px; }
	.xb1, .xb2, .xb3, .xb4 { display:block; overflow:hidden; }
	.xb1, .xb2, .xb3 { height:1px; }
	.xb2, .xb3, .xb4 { background:#fff; border-left:1px solid #444; border-right:1px solid #444; }
	.xb1 { margin:0 5px; background:#444; }
	.xb2 { margin:0 3px; border-width:0 2px; }
	.xb3 { margin:0 2px; }
	.xb4 { height:2px; margin:0 1px; }

	.xboxcontent { display:block; border:0 solid #444; border-width:0 1px; height:auto; }
	* html .xboxcontent { height:1px;  width:120px; }

<?php
	if ((($customHeader == 'none') || ($customHeader == '')) && (($customText == 'none') || ($customText == ''))) { ?>
		.color_a { background:#c9ba65; color:#fff; } /* beige */
		.color_b { background:#d4d8bd; color:#000; } /* pale green */
		.color_c { background:#758279; color:#fff; } /* dark grey */
		.color_d { background:#b2ab9b; color:#000; } /* light grey */
		.color_e { background:#dc143c; color:#fff; } /*  Crimson */
		.color_f { background:#ffe4c4; color:#000; } /*  bisque */
		.color_g { background:#0000ff; color:#fff; } /*  blue */
		.color_h { background:#a52a2a; color:#fff; } /*  brown */
		.color_i { background:#5f9ea0; color:#fff; } /*  cadetblue */
		.color_j { background:#7fff00; color:#000; } /*  chatreuse */
		.color_k { background:#00008b; color:#fff; } /*  darkblue */
		.color_l { background:#006400; color:#fff; } /*  dark green */
		.color_m { background:#bdb76b; color:#000; } /*  dark khaki */
		.color_n { background:#556b2f; color:#fff; } /*  olive green */
		.color_o { background:#ff8c00; color:#000; } /*  dark orange */
		.color_p { background:#8b0000; color:#fff; } /*  darkred */
		.color_q { background:#8fbc8f; color:#fff; } /*  dark seagreen */
		.color_r { background:#483d8b; color:#fff; } /*  slateblue */
		.color_s { background:#00bfff; color:#fff; } /*  skyblue */
		.color_t { background:#1e90ff; color:#fff; } /*  dodger blue */
		.color_u { background:#fffaf0; color:#000; } /*  floral white */
		.color_v { background:#dcdcdc; color:#000; } /*  gainsboro */
		.color_w { background:#ffd700; color:#000; } /*  gold */
		.color_x { background:#adff2f; color:#000; } /*  green yellow */
		.color_y { background:#f0fff0; color:#000; } /*  honey dew */
		.color_z { background:#e6e6fa; color:#000; } /*  lavendar */
		.color_aa { background:#add8e6; color:#000; } /*  light blue */
		.color_bb { background:#32cd32; color:#000; } /*  lime green */
		.color_cc { background:#66cdaa; color:#000; } /*  aquamarine */
		.color_dd { background:#c71585; color:#fff; } /*  violet red */
		.color_ee { background:#191970; color:#fff; } /*  midnight blue */
		.color_ff { background:#f5fffa; color:#000; } /*  mint cream */
		.color_gg { background:#ffa500; color:#000; } /*  orange */
		.color_hh { background:#ff4500; color:#fff; } /*  tomato red */
		.color_ii { background:#ff0000; color:#fff; } /*  red */
		.color_jj { background:#4169e1; color:#fff; } /*  royal blue */
		.color_kk { background:#2e8b57; color:#fff; } /*  sea green */
		.color_ll { background:#a0522d; color:#fff; } /*  sienna */
		.color_mm { background:#708090; color:#fff; } /*  slate grey */
		.color_nn { background:#fffafa; color:#000; } /*  snow */
		.color_oo { background:#4682b4; color:#fff; } /*  steal blue */
		.color_pp { background:#008080; color:#fff; } /*  teal */
		.color_qq { background:#f5deb3; color:#000; } /*  wheat */
		.color_rr { background:#f5f5f5; color:#000; } /*  white smoke */
		.color_ss { background:#9acd32; color:#fff; } /*  yellow green */
		.color_tt { background:#000000; color:#fff; } /*  black */
<?php
	} else { 
		$colorScheme = custom;
	?>
		.color_custom { background:#<?php echo $customHeader; ?>; color:#<?php echo $customText; ?>; } /*  custom */
<?php
	}
?>
</style>


<?php if ($params->get('JTSassuredmode')) { // If JTS Promotion Mode Use Below ?>

	<table width="100%" border="0" cellpadding="0" cellspacing="0" id="null" class="null" align="center">
		<tr>
			<td class="null" align="center">

				<div class="xsnazzy" style=" background: transparent; width:120px; margin:0 3px; padding:5px 10px;">

				<b class="xtop" style="width: 118px;">
					<b class="xb1" style="margin:0 5px; background:#ccc;"></b>
					<b class="xb2" style="border-left:1px solid #ccc; border-right:1px solid #ccc; background:transparent;"></b>
					<b class="xb3" style="border-left:1px solid #ccc; border-right:1px solid #ccc; background:transparent;"></b>
					<b class="xb4" style="border-left:1px solid #ccc; border-right:1px solid #ccc; background:transparent;"></b>
				</b>
				<div class="xboxcontent" style="width: 117px; height: 80px; border:0 solid #ccc; border-width:0 1px;">

				<div align='center' style="font-size: 10px;">
				<a style="font-weight: normal" href='http://joomlacode.org/gf/project/jts/' target='_jts'>
					<?php if ($isV15 == "1") { ?>
						<div style='background-image: url(modules/mod_jtsassured/mod_jtsassured/jts.gif); background-repeat: no-repeat; background-position: center; vertical-align: middle; text-align: center; height: 60px; width: 98px; vertical-align: middle;'></div>
					<?php } else { ?>
						<div style='background-image: url(modules/mod_jtsassured/jts.gif); background-repeat: no-repeat; background-position: center; vertical-align: middle; text-align: center; height: 60px; width: 98px; vertical-align: middle;'></div>
					<?php } ?>
				Test Your Site Today
				</a>
				</div>

				</div>

				<b class="xbottom" style="width: 118px;">
					<b class="xb4" style="border-left:1px solid #ccc; border-right:1px solid #ccc; background:transparent;"></b>
					<b class="xb3" style="border-left:1px solid #ccc; border-right:1px solid #ccc; background:transparent;"></b>
					<b class="xb2" style="border-left:1px solid #ccc; border-right:1px solid #ccc; background:transparent;"></b>
					<b class="xb1" style="margin:0 5px; background:#ccc;"></b>
				</b>
				</div>

			</td>
		</tr>
	</table>


<?php } else {  // If JTSc Rating Mode Use Below ?>



<?php
	// See if JTSc is installed and show the latest JTSc Rating if it is, otherwise show a download link...
	if (file_exists("administrator/components/com_jts/jts.xml")) {

		$jtsquery = "SELECT * FROM ". $mosConfig_dbprefix ."jts";
		$jtsresult = mysql_query ($jtsquery);


//			$database->setQuery( $jtsquery );
//			$rows = $database->loadObjectList();

			// Debug
			// print_r ($rows);

		while ( $jtsRating = mysql_fetch_array($jtsresult) )
		{
		// Rating Testing
		// $jtsRating['lastrate'] = '89';

			if ($isV15 == "1") {
				$rateIconPath = "modules/mod_jtsassured/mod_jtsassured/";
			} else {
				$rateIconPath = "modules/mod_jtsassured/";
			}

			if ($jtsRating['lastrate'] == '100') {
			$rateColor = "green"; $rateIcon = $rateIconPath ."100.png"; 
				} else if ($jtsRating['lastrate'] >= '95') { 
				$rateColor = "green"; $rateIcon = $rateIconPath ."095.png"; 
					} else if ($jtsRating['lastrate'] >= "90") {
					$rateColor = "orange"; $rateIcon = $rateIconPath ."090.png"; 
							} else { $rateColor = "red"; $rateIcon = $rateIconPath ."jts.gif"; 
			}
					// Debug
					// echo $jtsRating['lastrate'];

					// If Selected, Show JTS Logo if under 90%
					if (($jtsRating['lastrate'] < "90") && ($params->get('ratingNotAttained'))) {  // Show JTS Logo if JTS Rating less then 90% and user selecred to display logo
?>
					<div align="center">
						<a href='http://joomlacode.org/gf/project/jts/' target='_jts'>
							<div style='background-image: url(<?php echo $JTSLogo; ?>); background-repeat: no-repeat; background-position: center; vertical-align: middle; text-align: center; border: 1px solid #e6e6fa; padding: 5px; margin: 5px; height: 60px; width: 98px; vertical-align: bottom;'></div>
						</a>
					</div>
<?php

					// If Selected, Show Author Link if show JTS Logo if under 90% is also selected
					if ($params->get('authorLink')) { 
						echo "&nbsp;<a style='font-size: 7px; color: #C0C0C0; font-weight: normal; text-decoration: none;' href='http://www.justjoomla.com.au/' target='_justjoomla'>By JustJoomla!</a>"; 
					}

	} else if ($jtsRating['lastrate'] >= "90") {  // Only show JTS Assured if jtsRating is 90% or above
?>

	<table width="100%" border="0" cellpadding="0" cellspacing="0" id="null" class="null" align="center">
		<tr>
			<td class="null" align="center">

				<div class="xsnazzy">

				<b class="xtop">
					<b class="xb1"></b>
					<b class="xb2 color_<?php echo $colorScheme; ?>"></b>
					<b class="xb3 color_<?php echo $colorScheme; ?>"></b>
					<b class="xb4 color_<?php echo $colorScheme; ?>"></b>
				</b>
				<div class="xboxcontent" style="width: 118px;">

				<div align="center" class="h1 color_<?php echo $colorScheme; ?>">Joomla! Tools Suite</div>

					<div align="center">
					<?php if ($params->get('imageLinkJTS')) { echo "<a href='http://joomlacode.org/gf/project/jts/' target='_jts'>"; } ?>
							<div style='background-image: url(<?php echo $rateIcon; ?>); background-repeat: no-repeat; background-position: center; vertical-align: middle; text-align: center; padding: 5px; margin: 5px; height: 50px; width: auto; vertical-align: bottom;'></div>
					<?php if ($params->get('imageLinkJTS')) { echo "</a>"; } ?>
					</div>

					<div align="center" class="h2 color_<?php echo $colorScheme; ?>" style="text-align: center;">Assured Site</div>

				</div>

				<b class="xbottom">
					<b class="xb4 color_<?php echo $colorScheme; ?>"></b>
					<b class="xb3 color_<?php echo $colorScheme; ?>"></b>
					<b class="xb2 color_<?php echo $colorScheme; ?>"></b>
					<b class="xb1"></b>
				</b>
				</div>

	
	<?php
		// If Selected, Show Author Link even when over 90%
		if (($params->get('authorLink')) && ($jtsRating['lastrate'] >= "90")) { 
			echo "&nbsp;<a style='font-size: 7px; color: #C0C0C0; font-weight: normal; text-decoration: none;' href='http://www.justjoomla.com.au/' target='_justjoomla'>By JustJoomla!</a>"; 
		}
	?>
			</td>
		</tr>
	</table>

<?php
		}

	} // Above not shown if jtsRating is less than 90%


	} else { // JTSc was installed
		// JTSc not installed, show the download link
		If ($params->get('downloadLink')) {
			echo "<div align='center'>";
			echo "<a href='http://joomlacode.org/gf/project/jts/' target='_jts'>";
			if ($isV15 == "1") {
				echo "<div style='background-image: url(modules/mod_jtsassured/mod_jtsassured/jts.gif); background-repeat: no-repeat; background-position: center; vertical-align: middle; text-align: center; border: 1px solid #e6e6fa; padding: 5px; margin: 5px; height: 60px; width: 98px; vertical-align: bottom;'>Download</div>";
			} else {
			echo "<div style='background-image: url(modules/mod_jtsassured/jts.gif); background-repeat: no-repeat; background-position: center; vertical-align: middle; text-align: center; border: 1px solid #e6e6fa; padding: 5px; margin: 5px; height: 60px; width: 98px; vertical-align: bottom;'>Download</div>";
			}
			echo "</a>";
			echo "</div>";
		} else { // or show the JTS Logo instead
			echo "<a href='http://joomlacode.org/gf/project/jts/' target='_jts'><div style='vertical-align: middle; text-align: center; border: 1px solid #dc143c; background-color: #ffffcc; padding: 5px; margin: 5px; width: auto; height: auto; font-size: 9px; text-decoration: none; font-weight: normal;'><b>JTS Assured</b><br /><img src='". $downloadIcon."' border='0'><br />JTSc<br />Not Installed<br />Download Here</div></a>";
		} // End if JTS not installed Logo choice
	}


} // End JTSc Display Mode
?>
